﻿namespace Resharper.Abstractions.CodeDom.Statements.DeclarationStatements
{
  using JetBrains.Annotations;
  using JetBrains.ReSharper.Psi.CSharp.Tree;
  using Resharper.Abstractions.CodeDom.TreeNodes;
  using JetBrains.ReSharper.Psi.Util;

  /// <summary>Defines the <see cref="VariableDeclaration"/> class.</summary>
  public class VariableDeclaration : TreeNode
  {
    #region Constructors and Destructors

    /// <summary>Initializes a new instance of the <see cref="VariableDeclaration"/> class.</summary>
    /// <param name="localVariableDeclaration">The local variable declaration.</param>
    public VariableDeclaration(ILocalVariableDeclaration localVariableDeclaration) : base(localVariableDeclaration)
    {
    }

    #endregion

    #region Properties

    /// <summary>
    /// Gets the name.
    /// </summary>
    [NotNull]
    public string Name
    {
      get
      {
        return this.InternalLocalVariableDeclaration.DeclaredName ?? string.Empty;
      }
    }

    /// <summary>
    /// Gets the type.
    /// </summary>
    public Type Type
    {
      get
      {
        var type = this.InternalLocalVariableDeclaration.Type;

        return new Type(type, this.InternalLocalVariableDeclaration.Language);
      }
    }

    /// <summary>
    /// Gets the internal local variable declaration.
    /// </summary>
    [NotNull]
    internal ILocalVariableDeclaration InternalLocalVariableDeclaration
    {
      get
      {
        return (ILocalVariableDeclaration)this.InternalTreeNode;
      }
    }

    #endregion
  }
}